{php}$title = "后台首页";{/php}
{include file="layout/header" /}
<!--页面主要内容-->
<main class="lyear-layout-content">

  <div class="container-fluid p-t-15">

    <div class="row">
      <div class="col-md-12">
        <div class="card">
          <div class="card-header">
            <h6>选择数据来源（默认全部数据展示）</h6>
          </div>
          <div class="card-body">
            <div class="form-group">
              <div class="col-md-7">
                <select class="form-control" id="appselect">
                  <option value="">全部数据</option>
                </select>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>


    <div class="row">
      <div class="col-md-6 col-xl-3">
        <div class="card bg-primary text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-android fs-22"></i></span>
              <span class="fs-22 lh-22" id="apptotal">{$data.apptotal}</span>
            </div>
            <div class="text-right" >app数量</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-danger text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account-group fs-22"></i></span>
              <span class="fs-22 lh-22" id="usertotal">{$data.usertotal}</span>
            </div>
            <div class="text-right">用户总数</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-success text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-credit-card fs-22"></i></span>
              <span class="fs-22 lh-22" id="kmtotal">{$data.kmtotal}</span>
            </div>
            <div class="text-right">卡密总数</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-purple text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-comment-outline fs-22"></i></span>
              <span class="fs-22 lh-22" id="messagetotal">{$data.messagetotal}</span>
            </div>
            <div class="text-right">笔记总数</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 第二行 -->
    <div class="row">
      <div class="col-md-6 col-xl-3">
        <div class="card bg-info text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account fs-22"></i></span>
              <span class="fs-22 lh-22" id="todayregtotal">{$data.todayregtotal}</span>
            </div>
            <div class="text-right">今日注册</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-warning text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account-check fs-22"></i></span>
              <span class="fs-22 lh-22" id="todayviptotal">{$data.todayviptotal}</span>
            </div>
            <div class="text-right">会员数量</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-gray text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-credit-card-remove fs-22"></i></span>
              <span class="fs-22 lh-22" id="isusekmtotal">{$data.isusekmtotal}</span>
            </div>
            <div class="text-right">已使用卡密</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-brown text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-equalizer-outline fs-22"></i></span>
              <span class="fs-22 lh-22" id="viewtotal">{$data.viewtotal}</span>
            </div>
            <div class="text-right" >访问总数</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 第三行 -->
    <div class="row">
      <div class="col-md-6 col-xl-3">
        <div class="card bg-cyan text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account-edit fs-22"></i></span>
              <span class="fs-22 lh-22" id="signintotal">{$data.signintotal}</span>
            </div>
            <div class="text-right">今日签到人数</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-pink text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-message fs-22"></i></span>
              <span class="fs-22 lh-22" id="paltetotal">{$data.paltetotal}</span>
            </div>
            <div class="text-right" >板块数量</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-success text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-message-bulleted fs-22"></i></span>
              <span class="fs-22 lh-22" id="posttotal">{$data.posttotal}</span>
            </div>
            <div class="text-right" >帖子数量</div>
          </div>
        </div>
      </div>

      <div class="col-md-6 col-xl-3">
        <div class="card bg-dark text-white">
          <div class="card-body clearfix">
            <div class="flex-box">
              <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-cloud-upload fs-22"></i></span>
              <span class="fs-22 lh-22" id="filetotal">{$data.filetotal}</span>
            </div>
            <div class="text-right">附件数量</div>
          </div>
        </div>
      </div>
    </div>



    <div class="row">

      <div class="col-md-6">
        <div class="card">
          <div class="card-header">
            <div class="card-title">注册用户数量(统计数据库中最近的7天)</div>
          </div>
          <div class="card-body">
            <canvas class="js-chartjs-bars"></canvas>
          </div>
        </div>
      </div>

      <div class="col-md-6">
        <div class="card">
          <div class="card-header">
            <div class="card-title">每月用户总量(统计数据库中最近的7个月)</div>
          </div>
          <div class="card-body">
            <canvas class="js-chartjs-lines"></canvas>
          </div>
        </div>
      </div>

    </div>

    <div class="row">
      <div class="col-lg-12">
        <div class="card text-black">
          <header class="card-header">
            <div class="card-title">项目信息</div>
          </header>
          <div class="card-body">
            <table class="table table-hover">
              <tbody>
                <tr>
                  <td>项目名称：默然iApp后台管理系统</td>
                </tr>
                <tr>
                  <td>项目版本：<bb id="nowbb">2.6.0</bb>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="nowupdate()"
                      href="javascript:void(0)">检测更新</a></td>
                </tr>
                <tr>
                  <td>项目作者：默然</td>
                </tr>
                <tr>
                  <td>项目地址：<a href="https://gitee.com/morannb/moranht"
                      target="_blank">https://gitee.com/morannb/moranht</a></td>
                </tr>
                <tr>
                  <td>交&nbsp;&nbsp;流&nbsp;&nbsp;群：<a href="https://jq.qq.com/?_wv=1027&k=KNpWcDmS"
                      target="_blank">219348005</a></td>
                </tr>
                <tr>
                  <td>鸣&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;谢：<a href="http://lyear.itshubao.com/v4/index.html"
                      target="_blank">光年(Light Year Admin V4)后台管理系统模板</a></td>
                </tr>
                <tr>
                  <td>默然后台管理系统 是非盈利项目，开源不容易，如果该项目对你有用的话，可以打赏我们喝杯 coffee ☕️.
                  <td>
                </tr>
                <tr>
                  <td><img style="height: 300px;" src="https://www.moranblog.cn/zz/1.png" alt="" srcset="">
                  <td>
                  <td><img style="height: 300px;" src="https://www.moranblog.cn/zz/2.jpg" alt="" srcset="">
                  <td></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</main>
<!--End 页面主要内容-->
</div>
</div>
{include file="layout/footer" /}
<script type="text/javascript">
  var bb = $('#nowbb').html();
  $.ajax({
    type: "get",
    url: "{:url('index/getupdate')}",
    dataType: "json", //返回数据形式为json
    success: function (data) {
      if (data.code == 200) {
        if (bb != data.data.version) {
          $.notify({
            // options
            message: '有新版本发布，请及时更新！'
          }, {
            // settings
            type: 'warning',
          });
        }
      }
    }
  })


  function nowupdate() {
    var l = $('body').lyearloading({
      opacity: 0.2,
      spinnerSize: 'lg'
    });
    var bb = $('#nowbb').html();
    $.ajax({
      type: "get",
      url: "{:url('index/getupdate')}",
      dataType: "json", //返回数据形式为json
      success: function (data) {
        console.log(data);
        if (data.code == 200) {
          if (bb < data.data.version) {
            l.destroy();
            $.alert({
              title: '更新提示',
              icon: 'mdi mdi-alert',
              type: 'orange',
              content: '发现新版本，是否更新？' + '<hr>' + data.data.msg,
              buttons: {
                okay: {
                  text: '确认',
                  btnClass: 'btn-orange',
                  action: function () {
                    var l = $('body').lyearloading({
                      opacity: 0.2,
                      spinnerSize: 'lg',
                      spinnerText: '正在下载文件，请稍后...',
                      textColorClass: 'text-info',
                      spinnerColorClass: 'text-info'
                    });
                    $.ajax({
                      type: "post",
                      url: "{:url('index/downloadzip')}",
                      data: {
                        url: data.data.url
                      },
                      dataType: "json", //返回数据形式为json
                      success: function (res) {
                        if (data.code == 200) {
                          l.destroy();
                          $.alert({
                            title: '更新提示',
                            icon: 'mdi mdi-alert',
                            type: 'green',
                            content: '下载成功，更新文件已经保存在您的本地，请点击确定按钮进行更新',
                            buttons: {
                              okay: {
                                text: '确认',
                                btnClass: 'btn-orange',
                                action: function () {
                                  var l = $('body').lyearloading({
                                    opacity: 0.2,
                                    spinnerSize: 'lg',
                                    spinnerText: '解压文件中，请稍后...',
                                    textColorClass: 'text-info',
                                    spinnerColorClass: 'text-info'
                                  });
                                  $.ajax({
                                    type: "post",
                                    url: "{:url('index/unzip')}",
                                    data: {
                                      filepath: res.msg
                                    },
                                    dataType: "json", //返回数据形式为json
                                    success: function (datares) {
                                      l.destroy();
                                      if (datares.code == 200) {
                                        $.alert({
                                          title: '更新提示',
                                          icon: 'mdi mdi-alert',
                                          type: 'orange',
                                          content: '文件已解压成功，请点击确定按钮进行数据库更新，建议更新前先备份数据库',
                                          buttons: {
                                            okay: {
                                              text: '确认',
                                              btnClass: 'btn-orange',
                                              action: function () {
                                                var l = $('body').lyearloading({
                                                  opacity: 0.2,
                                                  spinnerSize: 'lg',
                                                  spinnerText: '更新数据库中，请稍后...',
                                                  textColorClass: 'text-info',
                                                  spinnerColorClass: 'text-info'
                                                });
                                                $.ajax({
                                                  type: "post",
                                                  url: "{:url('index/runsql')}",
                                                  dataType: "json", //返回数据形式为json
                                                  success: function (dataresq) {
                                                    if (dataresq.code == 200) {
                                                      l.destroy();
                                                      $.alert({
                                                        title: '更新提示',
                                                        icon: 'mdi mdi-alert',
                                                        type: 'green',
                                                        content: '更新成功！',
                                                      });
                                                    } else {
                                                      l.destroy();
                                                      $.alert({
                                                        title: '更新提示',
                                                        icon: 'mdi mdi-alert',
                                                        type: 'red',
                                                        content: '数据库更新失败，请稍后重试',
                                                      });
                                                    }
                                                  }
                                                });
                                              }
                                            }
                                          }
                                        });
                                      } else {
                                        $.alert({
                                          title: '更新提示',
                                          icon: 'mdi mdi-alert',
                                          type: 'red',
                                          content: '解压失败，请稍后重试',
                                        });
                                      }
                                    }
                                  });
                                }
                              }
                            }
                          });
                        } else {
                          l.destroy();
                          $.alert({
                            title: '更新提示',
                            icon: 'mdi mdi-alert',
                            type: 'red',
                            content: '下载失败，请稍后重试',
                          });
                        }
                      }
                    });
                  }
                }
              }
            });
          } else {
            l.destroy();
            $.alert({
              title: '成功提示',
              icon: 'mdi mdi-alert',
              type: 'green',
              content: '当前已是最新版本！',
            });
          }
        } else {
          l.destroy();
          $.alert({
            title: '错误提示',
            icon: 'mdi mdi-alert',
            type: 'red',
            content: "检查更新失败，请稍后再试！"
          });
        }
      }
    });
  }

  function date() {
    $.ajax({
      type: "get",
      url: "{:url('index/getWeekRegister')}",
      dataType: "json", //返回数据形式为json
      async: false, //同步传输，并添加返回值，返回值应为已定义的全局变量 如a
      success: function (data) {
        //console.log(data);
        a = data.data.date;
      }
    });
    return a;
  }
  function count() {
    $.ajax({
      type: "get",
      url: "{:url('index/getWeekRegister')}",
      dataType: "json", //返回数据形式为json
      async: false, //同步传输，并添加返回值，返回值应为已定义的全局变量 如a
      success: function (data) {
        a = data.data.count;
      }

    });
    return a;
  }
  function month() {
    $.ajax({
      type: "get",
      url: "{:url('index/getmonthusernum')}",
      dataType: "json", //返回数据形式为json
      async: false, //同步传输，并添加返回值，返回值应为已定义的全局变量 如a
      success: function (data) {
        a = data.data.date;
      }

    });
    return a;
  }
  function usernum() {
    $.ajax({
      type: "get",
      url: "{:url('index/getmonthusernum')}",
      dataType: "json", //返回数据形式为json
      async: false, //同步传输，并添加返回值，返回值应为已定义的全局变量 如a
      success: function (data) {
        a = data.data.count;
      }

    });
    return a;
  }
  $(document).ready(function (e) {
    var $dashChartBarsCnt = jQuery('.js-chartjs-bars')[0].getContext('2d'),
      $dashChartLinesCnt = jQuery('.js-chartjs-lines')[0].getContext('2d');
    var $dashChartBarsData = {
      labels: date().reverse(),
      datasets: [
        {
          label: '注册用户',
          borderWidth: 1,
          borderColor: 'rgba(0, 0, 0, 0)',
          backgroundColor: 'rgba(51, 202, 185, 0.5)',
          hoverBackgroundColor: "rgba(51, 202, 185, 0.7)",
          hoverBorderColor: "rgba(0, 0, 0, 0)",
          data: count().reverse()
        }
      ]
    };
    var $dashChartLinesData = {
      labels: month().reverse(),
      datasets: [
        {
          label: '用户数量',
          data: usernum().reverse(),
          borderColor: '#358ed7',
          backgroundColor: 'rgba(53, 142, 215, 0.175)',
          borderWidth: 1,
          fill: false,
          lineTension: 0.5
        }
      ]
    };

    new Chart($dashChartBarsCnt, {
      type: 'bar',
      data: $dashChartBarsData
    });

    var myLineChart = new Chart($dashChartLinesCnt, {
      type: 'line',
      data: $dashChartLinesData,
    });
  });

  //获取所有app
  $.ajax({
    type: "get",
    url: "{:url('index/getAllApp')}",
    dataType: "json", //返回数据形式为json
    async: false, //同步传输，并添加返回值，返回值应为已定义的全局变量 如a
    success: function (data) {
      //遍历到select中
      $.each(data.data, function (i, item) {
        $("#appselect").append("<option value='" + item.appid + "'>" + item.appname + "</option>");
      });
    }
  });

  $("#appselect").change(function () {
    var appid = $(this).val();
    console.log(appid);
    //ajax获取所有
    $.ajax({
      type: "post",
      url: "{:url('index/getAllChannel')}",
      data: {
        appid: appid
      },
      dataType: "json", //返回数据形式为json
      async: false, //同步传输，并添加返回值，返回值应为已定义的全局变量 如a
      success: function (data) {
        //console.log(data);
        $('#usertotal').html(data.data.usertotal);
        $('#kmtotal').html(data.data.kmtotal);
        $('#messagetotal').html(data.data.messagetotal);
        $('#todayviptotal').html(data.data.todayviptotal);
        $('#todayregtotal').html(data.data.todayregtotal);
        $('#isusekmtotal').html(data.data.isusekmtotal);
        $('#viewtotal').html(data.data.viewtotal);
        $('#signintotal').html(data.data.signintotal);
        $('#viewtotal').html(data.data.viewtotal);
        $('#paltetotal').html(data.data.paltetotal);
        $('#posttotal').html(data.data.posttotal);
      }
    });
  });
</script>
</body>

</html>